﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pavilion.GameTools;
using System.Xml.Linq;

namespace Pavilion.Locks
{
    public class MirrorCharacterInputLock : ILock
    {
        public CharacterInput RegularInput { get; set; }
        public CharacterInput MirrorInput { get; set; }
        public bool IsPressed { get; set; }
        public string GameItemName { get; set; }

        public ILock Clone()
        {
            return new MirrorCharacterInputLock()
            {
                GameItemName = this.GameItemName,
                RegularInput = this.RegularInput,
                MirrorInput = this.MirrorInput,
                IsPressed = this.IsPressed,
            };
        }

        public void Deserialize(XElement lockElement, string resourceName)
        {
            RegularInput = (CharacterInput)Enum.Parse(typeof(CharacterInput), lockElement.Attribute("RegularInput").Value);
            MirrorInput = (CharacterInput)Enum.Parse(typeof(CharacterInput), lockElement.Attribute("MirrorInput").Value);
            IsPressed = bool.Parse(lockElement.Attribute("IsPressed").Value);
        }

        public XElement Serialize()
        {
            XElement lockElement = new XElement("Lock");

            lockElement.Add(new XAttribute("RegularInput", RegularInput));
            lockElement.Add(new XAttribute("MirrorInput", MirrorInput));
            lockElement.Add(new XAttribute("IsPressed", IsPressed));

            return lockElement;
        }

        public LockMonitorBase CreateLockMonitor(GameItem gameItem)
        {
            return new MirrorCharacterInputLockMonitor(this);
        }

        public override string ToString()
        {
            return this.GetType().Name;
        }
    }
}
